package com.tanhua.web;

import com.tanhua.service.LoginService;
import com.tanhua.sso.pojo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("user")
public class LoginController {

    @Autowired
    private LoginService loginService;
    /*获取登录验证码
    * */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map<String,String> map){
        String phone=map.get("phone");
        //发送验证码
        ResponseEntity responseEntity = loginService.getCode(phone);
        //发送给前端
        return responseEntity;
    }

    /*手机号验证码,
    验证*/
    @PostMapping("loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String,String> map){
        Map<String,Object> newMap=loginService.loginVerification(map);
        return ResponseEntity.status(200).body(newMap);
    }

    //图片上传阿里云
    @PostMapping("/loginReginfo/head")
    public ResponseEntity head(MultipartFile headPhoto) throws IOException {
        loginService.head(headPhoto);
        return ResponseEntity.status(200).body("上传成功");
    }

    @PostMapping("loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo){
        loginService.loginReginfo(userInfo);
        return ResponseEntity.ok(null);
    }
}
